﻿Imports Control_Vuelos_BL
Imports Control_Vuelos_BE
Imports DevExpress.XtraGrid.Views.Grid

Public Class frmAdm_ValijaLista
    Inherits frmBaseMantenimiento

    Private _propertyName As UInteger
    Private ReadOnly _V_Valija As New V_ValijaBL()
    Private _CManifiestoBE As New C_ManifiestoBE
    Private ReadOnly _Manifiesto As New ManifiestoBL()
    Private p_CodViaje As String
    Private p_DesLugarOrigen As String
    Private p_DesLugarDestino As String
    Private p_NomEmpresa As String
    Private p_FchViaje As Date

    Private Sub frmAdm_ValijaLista_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        SG_Control_Vuelos_Main.RibbonPageGroup1.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup2.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup3.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup4.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup5.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup6.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup7.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup9.Visible = True
    End Sub

    Private Sub frmAdm_ValijaLista_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        AddHandler BarBtnModificar.ItemClick, AddressOf prl_Modificar
        AddHandler BarBtnImprimir.ItemClick, AddressOf prl_ValijaImpresion
        AddHandler BarBtnRefresh.ItemClick, AddressOf prl_Refresh
        BarBtnModificar.Caption = "Registrar"
        BarBtnEliminar.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
        prl_Refresh()
    End Sub

    Public Sub prl_Refresh()
        GridControl1.DataSource = _V_Valija.pr_Valijas.Tables("Valijas")
        GridView1.SetRowExpanded(-1, True, True)
    End Sub

    Public Sub prl_ValijaImpresion()
        Dim _Valija As New V_ValijaBL
        Dim RptValija As New XRptValija
        RptValija.lbRuta.Text = String.Format("{0} - {1}", p_DesLugarOrigen, p_DesLugarDestino)
        RptValija.lbFecha.Text = p_FchViaje
        RptValija.lbNomEmpresa.Text = p_NomEmpresa
        RptValija.DataSource = _Valija.pr_ListarValijasImpresion(p_CodViaje)
        RptValija.DataMember = "Valija"
        RptValija.ShowRibbonPreviewDialog()
    End Sub

    Private Sub prl_Modificar()
        If Not p_CodViaje Is Nothing Then
            _CManifiestoBE = _Manifiesto.pr_RecuperarCabecera(p_CodViaje)
            Using sfrmValija As New frmAdm_Valija()
                sfrmValija.p_CodViaje = _CManifiestoBE.CodViaje
                sfrmValija.p_FchViaje = _CManifiestoBE.FchViaje
                sfrmValija.p_NroValija = _CManifiestoBE.NroValija
                Dim oDialogResult As System.Windows.Forms.DialogResult = sfrmValija.ShowDialog(Me)
                If oDialogResult = System.Windows.Forms.DialogResult.OK Then
                    GridControl1.DataSource = _V_Valija.pr_Valijas.Tables("Valijas")
                    GridView1.SetRowExpanded(-1, True, True)
                End If
            End Using
        End If
    End Sub

    Private Sub GridView1_FocusedRowChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles GridView1.FocusedRowChanged
        Dim row As DataRow = TryCast(GridView1.GetDataRow(GridView1.GetSelectedRows()(0)), DataRow)
        If Not row Is Nothing Then
            p_CodViaje = row("CodViaje")
            p_DesLugarDestino = row("DesDestino")
            p_DesLugarOrigen = row("DesOrigen")
            p_FchViaje = row("FchViaje")
            p_NomEmpresa = row("NomEmpresa")
        End If
    End Sub

    Private Sub GridView2_FocusedRowChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles GridView2.FocusedRowChanged
        Dim view As GridView = TryCast(sender, GridView)
        Dim row As DataRow = TryCast(GridView1.GetDataRow(view.SourceRowHandle), DataRow)
        If Not row Is Nothing Then
            p_CodViaje = row("CodViaje")
            p_DesLugarDestino = row("DesDestino")
            p_DesLugarOrigen = row("DesOrigen")
            p_FchViaje = row("FchViaje")
            p_NomEmpresa = row("NomEmpresa")
        End If
    End Sub
End Class